import storage from '@/utils/storage.js'

const StorgeKey = {
	goodsItem: 'directPurchase_goodsItem',
	goodsCount: 'directPurchase_goodsCount',
}

// 直接购买store
export default {
	state: {
		goodsItem: storage.get(StorgeKey.goodsItem, null),
		goodsCount: storage.get(StorgeKey.goodsCount, 0),
	},
	mutations: {
		SET_goodsItem(state, item) {
			state.goodsItem = item
			storage.set(StorgeKey.goodsItem, item)
		},
		SET_goodsCount(state, count) {
			state.goodsCount = count
			storage.set(StorgeKey.goodsCount, count)
		}
	},
	actions: {
		// 添加直购商品
		ac_directPurchase_join_goodsItem({
			commit
		}, item) {
			commit('SET_goodsItem', item)
			commit('SET_goodsCount', 1)
		},
		// 删除直购商品
		ac_directPurchase_clear_goodsItem() {
			commit('SET_goodsItem', null)
			commit('SET_goodsCount', 0)
		}
	},
	getters: {
		directPurchaseGoodsItem:state=>state.goodsItem,
		directPurchaseGoodsCount:state=>state.goodsCount,
	}
}